﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pub;

namespace LZQXT.Test.Forms.Script
{
    public partial class FJS : Form
    {
        string sJsFile = "";
        public FJS()
        {
            InitializeComponent();
        }

        private void toolOpen_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Js文件|*.js|所有文件|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                sJsFile = openFileDialog1.FileName;
                tboxJsCode.LoadFile(sJsFile, true, true);

            }
        }

        private void toolRun_Click(object sender, EventArgs e)
        {
            try
            {
                tboxJsOutput.Text = CExp.getVal(tboxJsCode.Text);
            }
            catch (System.Exception ex)
            {
                tboxJsOutput.Text = ex.ToString();
                CDebug.SendError(ex.ToString());
                //MessageBox.Show(ex.ToString());
            }
        }

        private void toolSave_Click(object sender, EventArgs e)
        {
            if (sJsFile == string.Empty)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    sJsFile = saveFileDialog1.FileName;

                    if (CPub.MsgBox("确定要保存到'" + sJsFile + "'吗?", "保存"))
                    {
                        //tboxJsCode.SaveFile(tboxJsFile.Text, RichTextBoxStreamType.PlainText);
                        tboxJsCode.SaveFile(sJsFile);
                    }
                }
            }
        }

        private void FJS_Load(object sender, EventArgs e)
        {
            tboxJsCode.Dock = DockStyle.Fill;

            CTextEditMenu richMenu2 = new CTextEditMenu(tboxJsCode);
            
            openFileDialog1.InitialDirectory = Application.StartupPath;
        }

        private void toolSaveAs_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                sJsFile = saveFileDialog1.FileName;
                tboxJsCode.SaveFile(sJsFile);
            }
        }
    }
}
